<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="./css/animate.css">
    <script src="./js/vue.js"></script>
    <style>
        #app{
            padding:10px;
            margin-bottom:400px;

        }
        .child1{
            margin:20px;
            padding:10px;
            background-color: #cccccc;
            position:absolute;
            width: 80%;
        }
        .child2{
            margin:20px;
            padding:10px;
            background-color: #35cf20;
            position:absolute;
            width: 80%;
        }
        .begin1{
            opacity: 1;
            transform: translateX(0px);
        }
        .active{
            transition: all 3s ease;
        }
        .end{
            opacity: 1;
            transform: translateX(0px);
        }
        .end1{
            opacity: 0;
            transform: translateX(-100%);
        }

    </style>
</head>
<body>
    <div id="app">
        <h3>父组件</h3>


        <input type="button" value="显示|隐藏" @click=" flag=!flag ">
        <input type="button" value="显示-one" @click=" name='ChildOne' ">
        <input type="button" value="显示-two" @click=" name='ChildTwo' ">

        <!-- 
            元素由不显示到显示的执行过程
            enter-class - string
            enter-active-class - string
            enter-to-class - string

            leave-class - string
            leave-active-class - string
            leave-to-class - string
        -->
        <!-- <transition-group
            enter-class="begin" enter-active-class="active" enter-to-class="end"
            leave-class="begin1" leave-active-class="active" leave-to-class="end1"
        >
            <div v-show="flag" class="child1" key="1">
                <h3>测试标签1</h3>
            </div>
            <div v-show="!flag" class="child2" key="2">
                <h3>测试标签2</h3>
            </div>
        </transition-group> -->

        <transition 
            enter-class="begin" enter-active-class="active" enter-to-class="end"
            leave-class="begin1" leave-active-class="active" leave-to-class="end1"    
        >
            <keep-alive>
                <component :is="name"></component>
            </keep-alive>
        </transition>

        <!-- 
            过渡组件本身就是基于 动态添加class方式实现动画的执行
            所以开发时可以直接提供具有动画效果的样式即可
         -->
        
        <!-- <transition enter-active-class="animated fadeInRight" leave-active-class="animated fadeOutLeft">
            <keep-alive>
                <component :is="name"></component>
            </keep-alive>
        </transition> -->
    </div>
    <template id="ChildOne">
        <div class="child1" id="组件One">
            <h3>子组件one</h3>
        </div>
    </template>
    <template id="ChildTwo">
        <div class="child2" id="组件Two">
            <h3>子组件two</h3>
        </div>
    </template>
</body>
<script>
    Vue.component("ChildOne",{
        template:"#ChildOne"
    })
    Vue.component("ChildTwo",{
        template:"#ChildTwo"
    })
    new Vue({
        el:"#app",
        data:{
            flag:false,
            name:"ChildOne"
        }
    })
</script>
</html>